<?php
class DigNavigation_Plugin_Routing extends Zend_Controller_Plugin_Abstract {

    public function preDispatch(Zend_Controller_Request_Abstract $request) {
        // Dig_Service_Firebug::profile('routing');
        $uri = $_SERVER['REQUEST_URI'];
        $cleanUri = DigNavigation_Service_Url::stripParams($uri);
        $params = DigNavigation_Service_Url::getParams($uri);
        if($params) {
            foreach ($params as $key => $value) {
                $request->setParam($key, $value);
            }
        }
        $item = DigNavigation_Service_Menu::mapUrlToItem($cleanUri);
        if($item) {
            $itemType = DigCms_Service_Item::getItemType($item);
            if(is_array($itemType)) {
                $request->setModuleName($itemType['module']);
                $request->setControllerName($itemType['controller']);
                $request->setActionName('render');
                $request->setParam(DigCms_Library_Item_Controller::CURRENT_ITEM, $item);
            }
        }
    }
}
?>